﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IPC.Communication.Framework.BasicFramework;

namespace IPC.Communication.Framework.Serial
{
    public class SoftLRC
    {
        public static byte[] LRC(byte[] value)
        {
            if (value == null)
            {
                return null;
            }
            int num = 0;
            for (int i = 0; i < value.Length; i++)
            {
                num += value[i];
            }
            num %= 256;
            num = 256 - num;
            byte[] array = new byte[1]
		{
			(byte)num
		};
            return SoftBasic.SpliceArray<byte>(value, array);
        }

        public static bool CheckLRC(byte[] value)
        {
            if (value == null)
            {
                return false;
            }
            int num = value.Length;
            byte[] array = new byte[num - 1];
            Array.Copy(value, 0, array, 0, array.Length);
            byte[] array2 = LRC(array);
            if (array2[num - 1] == value[num - 1])
            {
                return true;
            }
            return false;
        }
    }
}
